﻿/**
 * @file   InpReadInformationMapper.h
 * @brief inp读取信息映射表-用于读完的信息整合
 * @author liuzhonghua (liuzhonghuaszch@163.com)
 * @date 2024-06-21
 */
#ifndef __INPREADINFORMATION_MAPPER_H__
#define __INPREADINFORMATION_MAPPER_H__

#include <QMultiHash>
#include <QPair>
#include <QStringList>

namespace Interface
{
    class FITKAbaAssembly;
    class FITKAbstractModel;
    class FITKAbstractSection;
    class FITKModelSet;
    class FITKAbaAbstractBoundaryCondition;
    class FITKAbaAbstractLoad;
    class FITKAbaAbstractInertia;
    class FITKAbaTransform;
    class FITKAbaAbstractSpringDashpot;
    class FITKAbaConnectorSection;
    class FITKAbaConnectorAssignment;
    class FITKAbaAssEleCONN3D2;
}
namespace AbaqusData
{
    class FITKDataCase;
    class FITKAbaqusPart;
}

namespace IO
{
    /**
     * @brief 行数据
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date 2024-06-21
     */
    struct ElementPointInfo
    {
        /**
         * @brief 单元编号
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-24
         */
        int _idElement = 0;
        /**
         * @brief 一行点的数据
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-24
         */
        QList<QPair<int, int>> _elementPointData;
    };
    /**
     * @brief ElementDataInfo 单元的信息
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date 2024-06-21
     */
    struct InpElementDataInfo
    {
        /**
         * @brief 单元类型
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-21
         */
        QString _elementType;
        /**
         * @brief ElementName
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-21
         */
        QString _elesetName;
        /**
         * @brief 模型id
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-21
         */
        int _modelId = 0;
        /**
         * @brief 列数据
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-21
         */
        QList<struct ElementPointInfo> _elementMap;
    };
    /**
     * @brief OrientationInfo 
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date 2024-06-24
     */
    struct InpOrientationInfo
    {
        /**
         * @brief ElementName
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-21
         */
        int _csysId;
        /**
         * @brief 模型id
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-21
         */
        int _modelId = 0;
        /**
         * @brief 
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-21
         */
        QString _secondLine;
    };
    /**
     * @brief InpConnectorSectionInfo
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date 2024-06-24
     */
    struct InpConnectorSectionAssignInfo
    {
        /**
         * @brief 连接器section数据
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-24
         */
        Interface::FITKAbaConnectorSection* _sectionData{};
        /**
         * @brief 集合名称
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-24
         */
        QString _elset{};
        /**
         * @brief 行为名称
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-24
         */
        QString _behavior{};
        /**
         * @brief 坐标系1名称
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-24
         */
        QString _csysName1{};
        /**
         * @brief 坐标系2名称
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-24
         */
        QString _csysName2{};
    };
    /**
     * @brief inp读取信息映射表
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date 2024-06-21
     */
    class InpReadInformationMapper
    {
    public:
        /**
         * @brief Construct a new Inp Read Information Mapper object
         * @param[i]  caseData       算例
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-21
         */
        explicit  InpReadInformationMapper(AbaqusData::FITKDataCase* caseData );
        ~InpReadInformationMapper();
        /**
         * @brief 插入section数据和材料名称
         * @param[i]  section        section对象
         * @param[i]  materialName            材料名称
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-03-24
         */
        void insertSectionDataMaterialName(Interface::FITKAbstractSection* sectionData, QString materialName);
        /**
         * @brief 插入集合数据和局部坐标系名称
         * @param[i] setData 集合对象
         * @param[i] tranformName 局部坐标系名称
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-21
         */
        void insertSetDataTransformName(Interface::FITKModelSet* setData, QString tranformName);
        /**
         * @brief 插入Orientation数据
         * @param[i] transformData 局部坐标系name
         * @param[i] csysId 局部坐标系id
         * @param[i] modelId 模型id
         * @param[i] secondLine inp文件中Orientation关键字下的第二行数据
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-21
         */
        void insertOrientationInfoData(QString name, int csysId, int modelId, QString secondLine);
        /**
         * @brief 获取inp文件中Orientation关键字下的第二行数据和局部坐标系id
         * @param[i] name OrientationName
         * @param[i] modelId 模型id
         * @param[o] csysId 模型id  err:id = 0
         * @return 第二行数据
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-21
         */
        QString getOrientationSecondLine(QString name, int modelId, int& csysId);
        /**
         * @brief 插入element信息数据
         * @param[i] info element信息数据
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-21
         */
        void insertElementInfo(InpElementDataInfo* info);
        /**
         * @brief 插入连接器截面指派信息
         * @param[i] assignData 指派数据
         * @param[i] info 连接器信息
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-24
         */
        void insertConnectorAssignment(Interface::FITKAbaConnectorAssignment* assignData, InpConnectorSectionAssignInfo* info);
        /**
         * @brief 插入连接器单元信息
         * @param elementId inp文件里的id编号
         * @param element 新线单元
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-07-02
         */
        void insertElementConnect(int elementId, Interface::FITKAbaAssEleCONN3D2* element);
        /**
         * @brief 获取连接器截面通过行为名称
         * @param[i] behaviorName 行为名称
         * @return Interface::FITKAbaConnectorSection* 连接器截面
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-24
         */
        Interface::FITKAbaConnectorSection* getConnectorSectionByBehaviorName(QString behaviorName);
        /**
         * @brief 进行信息映射
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-21
         */
        void map();

    private:
        /**
         * @brief 材料与section映射
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-21
         */
        void materialSectionMap();
        /**
         * @brief Transform与集合的映射 -boundary,load设置局部坐标系
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-21
         */
        void transformSetMap();
        /**
         * @brief element与Inertia的映射
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-21
         */
        void elementInertiaMap();
        /**
         * @brief element与弹簧的映射
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-22
         */
        void elementSpringDashpotMap();
        /**
         * @brief 连接器Section与指派器的映射
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-27
         */
        void connectSectionAssignMap();
        /**
         * @brief 连接器集合里的单元id修改
         * @param[i] setData 集合数据
         * @return 状态
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-07-02
         */
        bool connectSetElementIdRevise(Interface::FITKModelSet* setData);
        /**
         * @brief 设置弹簧
         * @param data 弹簧数据
         * @param model 模型
         * @return 状态
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-22
         */
        bool setElementSpringDashpot(Interface::FITKAbaAbstractSpringDashpot* data, Interface::FITKAbstractModel* model);
        /**
         * @brief 对比弹簧是否类型一致
         * @param type 类型
         * @param data 弹簧数据
         * @return true一致 false不一致
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-22
         */
        bool compareSpringDashpotTypeData(QString type, Interface::FITKAbaAbstractSpringDashpot* data);
        /**
         * @brief 设置装配惯量/质量点
         * @param inertia 惯量/质量点
         * @param model 模型
         * @param index 
         * @return 状态
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-05-30
         */
        bool setElementInertia(Interface::FITKAbaAbstractInertia* inertia, Interface::FITKAbstractModel* model, int index);
        /**
         * @brief 对比惯量/质量点是否类型一致
         * @param type 类型
         * @param inertia 惯量数据
         * @return true一致 false不一致
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-13
         */
        bool compareInertiaTypeData(QString type, Interface::FITKAbaAbstractInertia* inertia);


    private:
       /**
        * @brief 算例数据对象
        * @author LiBaojun (libaojunqd@foxmail.com)
        * @date 2024-03-24
        */
        AbaqusData::FITKDataCase* _caseData{};
        /**
         * @brief section与材料的对应映射
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-03-24
         */
        QHash<Interface::FITKAbstractSection*, QStringList> _materials{};
        /**
         * @brief 集合与Transform的对应映射
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-21
         */
        QHash<Interface::FITKModelSet*, QString> _setTransformMap{};
        /**
         * @brief Orientation与第二行的数据映射
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-21
         */
        QMultiHash<QString, struct InpOrientationInfo*> _orientationDataMap{};
        /**
         * @brief elementData数据信息
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-21
         */
        QList<struct InpElementDataInfo*> _elementDataInfo{};
        /**
         * @brief 连接器section指派数据映射 assign, QList<setName, csys1, csys2>
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-06-24
         */
        QHash<Interface::FITKAbaConnectorAssignment*, InpConnectorSectionAssignInfo*> _connAssignSectionMap{};
        /**
         * @brief 连接器单元映射
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-07-02
         */
        QHash<int, Interface::FITKAbaAssEleCONN3D2*> _elementConnect{};
    };

}


#endif
